package com.sf.dlb.jpa.repository;

import com.sf.dlb.jpa.model.WalletEthAddressInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


/**
 * 用户eth地址表 Repository
 *
 * Created by jing.tan on 2018/5/21.
 */
@Repository
public interface WalletEthAddressRepository extends JpaRepository<WalletEthAddressInfo, Long> {
    /**
     * 根据用户查询
     * @param userId
     * @param delFlag
     * @return
     */
    WalletEthAddressInfo findByUserIdAndDelFlag(String userId, String delFlag);
    /**
     * 未被绑定的地址数量
     */
    @Query(value = "select count(*) from wallet_eth_address a where a.user_id is null or a.user_id=''",nativeQuery = true)
    Integer notBandingAddressCount();
    /**
     * 获取一个未被绑定的地址
     */
    @Query(value = "select * from wallet_eth_address a where a.user_id is null or a.user_id='' LIMIT 0,1",nativeQuery = true)
    WalletEthAddressInfo getOneNotBandingAddress();

}